package com.example.harmonet.harmtorch;

public class Softmax implements Layer {

    @Override
    public Tensor forward(Tensor in) {
        Tensor out = new Tensor(in.dim());
        float sum = (float)0.01;
        for(int i = 0 ; i < in.tensor().length; ++i) {
            out.tensor()[i] = (float) Math.exp(in.tensor()[i]);
            sum += out.tensor()[i];
        }
        for(int i = 0; i < out.tensor().length; ++i) {
            out.tensor()[i] /= sum;
        }
        return out;
    }

    @Override
    public int getParam() {
        return 0;
    }

    @Override
    public void init(float[] param) {
    }
}
